<?php
$hide=$_REQUEST["hide"];
$conn=mysqli_connect("127.0.0.1","root","","huawei");
mysqli_query($conn,"SET NAMES utf8");
if($hide=="testphone"){
   $sql="SELECT phone FROM user";
   $result=mysqli_query($conn,$sql);
   $arr=[];
   while(($row=mysqli_fetch_assoc($result))!=null){
      array_push($arr,$row);
   }
	echo $_GET["callback"]."(".JSON_encode($arr).")";
}else if($hide=="register") {
    $phone=$_REQUEST["phone"];
    $pwd=$_REQUEST["pwd"];
    $sql="INSERT INTO user VALUES(0,'$phone','$pwd')";
    $result=mysqli_query($conn,$sql);
    if($result){
        echo ("<script>alert('注册成功');location='logon.html'</script>");
    }else{
        echo ("<script>alert('注册失败，重新注册');location='Register.html'</script>");
    }  
}else if($hide=="logon") {

    $phone=$_REQUEST["phone"];
    $pwd=$_REQUEST["pwd"];
    $sql="SELECT pwd FROM user WHERE phone='$phone'";
    $result=mysqli_query($conn,$sql);
    $row=mysqli_fetch_row($result);
    if($row[0]==$pwd){
        echo $_GET["callback"]."(".("<script>document.cookie='phone=$phone';location='index.html'</script>").")";
    }else{
        echo $_GET["callback"]."(".("<script>alert('密码错误');location='logon.html'</script>").")";
    }
}else if($hide=="mate") {
    $sql="SELECT*FROM phonesmate";
    $result=mysqli_query($conn,$sql);
    $arr=[];
    while(($row=mysqli_fetch_assoc($result))!=null){
        array_push($arr,$row);
     }
      echo $_GET["callback"]."(".JSON_encode($arr).")";  
}else if($hide=="matephone") {
    $id=$_REQUEST["id"];
    $sql="SELECT*FROM phonesmate WHERE id=$id";
    $result=mysqli_query($conn,$sql);
    $row=mysqli_fetch_assoc($result);
    echo $_GET["callback"]."(".JSON_encode($row).")";  
}
else if($hide=="phonecolor") {
    $id=$_REQUEST["id"];
    $sql="SELECT*FROM phonesmate WHERE id=$id";
    $result=mysqli_query($conn,$sql);
    $row=mysqli_fetch_assoc($result);
    echo $_GET["callback"]."(".JSON_encode($row).")";  
}
else if($hide=="shopcart"){
    $phone=$_REQUEST["phone"];
    $money=$_REQUEST["money"];
    $color=$_REQUEST["color"];
    $ram=$_REQUEST["ram"];
    $taocan=$_REQUEST["taocan"];
    $img=$_REQUEST["img"];
    $count=$_REQUEST["count"];
    $peoplenum=$_REQUEST["people"];
    $jieshao=$_REQUEST["jieshao"];
    $sql="INSERT INTO cart VALUES(0,'$phone','$money','$color','$ram','$taocan','$img','$count','$peoplenum','$jieshao')";
    $result=mysqli_query($conn,$sql);
    if($result){
        echo ("<script>alert('添加商品成功');location='huawei-mates.html'</script>");
    }else{
        echo ("<script>alert('添加商品失败');location='huawei-mate.html'</script>");
    }
}
else if($hide=="cartplease") {
    $sql="SELECT*FROM cart";
    $result=mysqli_query($conn,$sql);
    $arr=[];
    while(($row=mysqli_fetch_assoc($result))!=null){
        array_push($arr,$row);
   }
    echo $_GET["callback"]."(".JSON_encode($arr).")";  
}else if($hide=="rxdanpin") {
    $sql="SELECT*FROM rxdanpin";
    $result=mysqli_query($conn,$sql);
    $arr=[];
    while(($row=mysqli_fetch_assoc($result))!=null){
        array_push($arr,$row);
   }
    echo $_GET["callback"]."(".JSON_encode($arr).")";  
}else if($hide=="jptuijian") {
    $sql="SELECT*FROM jptuijian";
    $result=mysqli_query($conn,$sql);
    $arr=[];
    while(($row=mysqli_fetch_assoc($result))!=null){
        array_push($arr,$row);
   }
    echo $_GET["callback"]."(".JSON_encode($arr).")";  
}
else if($hide=="banner") {
   
        $sql="SELECT * FROM lunbo";
        $result=mysqli_query($conn,$sql);
        $arr=[];
        while(($row=mysqli_fetch_assoc($result))!=null){
            array_push($arr,$row);
        }
        echo $_GET["callback"]."(".JSON_encode($arr).")"; 
}
else if($hide=="zhscreen") {
   
    $sql="SELECT * FROM screen";
    $result=mysqli_query($conn,$sql);
    $arr=[];
    while(($row=mysqli_fetch_assoc($result))!=null){
        array_push($arr,$row);
    }
    echo $_GET["callback"]."(".JSON_encode($arr).")"; 
}
else if($hide=="delete") {
    $id=$_REQUEST["id"];
    $sql="DELETE FROM cart WHERE id=$id";
    $result=mysqli_query($conn,$sql);
}

    mysqli_close($conn);
?>